package com.redstars.generate.controller;


import com.redstars.generate.page.PageResult;
import com.redstars.generate.query.SysProjectQuery;
import com.redstars.generate.result.Result;
import com.redstars.generate.service.SysProjectService;
import com.redstars.generate.vo.SysProjectVo;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;
import java.util.List;

/**
* 项目
*
* @author zhouhx 
* @since 1.0.0 2022-10-14
*/
@RestController
@RequestMapping("gen/project")
@AllArgsConstructor
public class SysProjectController {
    private final SysProjectService SysProjectService;

    @GetMapping("page")
    public Result<PageResult<SysProjectVo>> page(@Valid SysProjectQuery query){
        PageResult<SysProjectVo> page = SysProjectService.page(query);

        return Result.ok(page);
    }

    @GetMapping("{id}")
    public Result<SysProjectVo> detail(@PathVariable("id") Long id){
        SysProjectVo detail = SysProjectService.detail(id);

        return Result.ok(detail);
    }

    @PostMapping
    public Result<String> save(@RequestBody SysProjectVo vo){
        SysProjectService.save(vo);

        return Result.ok();
    }

    @PutMapping
    public Result<String> update(@RequestBody @Valid SysProjectVo vo){
        SysProjectService.update(vo);

        return Result.ok();
    }

    @DeleteMapping
    public Result<String> delete(@RequestBody List<Long> idList){
        SysProjectService.delete(idList);

        return Result.ok();
    }

    @GetMapping("list")
    public Result<List<SysProjectVo>> list(SysProjectQuery query){
        List<SysProjectVo> list = SysProjectService.list(query);

        return Result.ok(list);
    }
}